package own.stu.jobgib.playown.fsm.easyStates.core;

import lombok.Data;
import own.stu.jobgib.playown.fsm.easyStates.api.Event;
import own.stu.jobgib.playown.fsm.easyStates.api.EventHandler;
import own.stu.jobgib.playown.fsm.easyStates.api.State;
import own.stu.jobgib.playown.fsm.easyStates.api.Transition;

@Data
public class TransitionImpl<E extends Event> implements Transition {

    private String name;

    private State sourceState;

    private State targetState;

    private Class<E> eventType;

    private EventHandler<E> eventHandler;

    @Override
    public String getName() {
        return this.name;
    }

    @Override
    public State getSourceState() {
        return this.sourceState;
    }

    @Override
    public State getTargetState() {
        return this.targetState;
    }

    @Override
    public Class<? extends Event> getEventType() {
        return this.eventType;
    }

    @Override
    public EventHandler getEventHandler() {
        return this.eventHandler;
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        TransitionImpl that = (TransitionImpl) o;

        return eventType.equals(that.eventType) && sourceState.equals(that.sourceState);
    }

    public String toString() {
        final StringBuilder sb = new StringBuilder();
        sb.append("Transition");
        sb.append("{name='").append(name).append('\'');
        sb.append(", sourceState=").append(sourceState.getName());
        sb.append(", targetState=").append(targetState.getName());
        sb.append(", eventType=").append(eventType);
        if (eventHandler != null) {
            sb.append(", eventHandler=").append(eventHandler.getClass().getName());
        }
        sb.append('}');
        return sb.toString();
    }
}
